import { TakeGoodsAction } from '../actions'
import { SimpleType } from '../Types'
import { 
  GetTakeGoodsList_PENDING, 
  GetTakeGoodsList_FULFILLED, 
  GetTakeGoodsList_PAGE, 
  RECORD_TakeGoods_FULFILLED } from '../Constants'
// 初始化
const initState= {
  loading: false,
  record: {},
  data: {
    list: [],
    pagination: {}
  }
}
export function TakeGoodsReducer(state: SimpleType = initState, action: TakeGoodsAction): SimpleType {
  switch (action.type) {
    case GetTakeGoodsList_PENDING:
      return { ...state, loading: true }
    case GetTakeGoodsList_FULFILLED:
      return { 
        ...state, 
        loading: false, 
        data: { 
          list: action.payload.list, 
          pagination: {
            ...state.data.pagination,
            total: action.payload.recordsTotal 
          } 
        } 
      }
    case GetTakeGoodsList_PAGE:
      return {
        ...state,
        data: { 
          pagination:{
            ...state.data.pagination,
            current: action.payload.current || 1,
            pageSize: action.payload.pageSize || 10
          }
        } 
      }
    case RECORD_TakeGoods_FULFILLED:
      return {
        ...state,
        record: action.payload
      }
  }
  return state
}